<template>
  <div class="history-container">
    <el-form ref="formRef" :model="pamars" inline>
      <!-- <el-form-item label="转赠人手机号" prop="give_mobile">
        <el-input v-model="pamars.give_mobile" placeholder="请输入"></el-input>
      </el-form-item> -->
      <el-form-item label="被余额(消费额余额)人手机号" prop="realName">
        <el-input v-model="pamars.realName" placeholder="请输入"></el-input>
      </el-form-item>
      <el-form-item label="转赠时间">
        <el-date-picker
          v-model="timer"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="timerChange"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="success" @click="getDataList()">查询</el-button>
        <el-button type="warning" @click="resetPamars()">重置</el-button>
      </el-form-item>
      <el-form-item v-if="isBack">
        <el-button @click="goBack">返回</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" row-key="Id" border stripe style="width: 100%">
      <el-table-column type="index" align="center" width="100px" label="序号">
      </el-table-column>
      <!-- <el-table-column prop="give_real_name" align="center" label="转赠人">
      </el-table-column> -->
      <el-table-column prop="real_name" align="center" label="被余额(消费额余额)人">
        <template slot-scope="scoped">
          <div>{{ scoped.row.real_name }}({{ scoped.row.mobile }})</div>
        </template>
      </el-table-column>
      <el-table-column prop="give_point" align="center" label="转赠积分数">
        <template slot-scope="scoped">
          <div>
            {{ isToFixed(scoped.row.give_point, 8) }}
          </div>
        </template>
      </el-table-column>
      <!-- <el-table-column prop="handling_fee" align="center" label="转赠手续费">
        <template slot-scope="scoped">
          <div>
            {{ isToFixed(scoped.row.handling_fee, 8) }}
          </div>
        </template>
      </el-table-column> -->
      <el-table-column prop="create_time" align="center" label="转赠时间">
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pamars.page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pamars.limit"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </div>
</template>

<script>
import seviceApi from '@/api/serviceApi.js'
export default {
  data() {
    return {
      timer: null,
      pamars: {
        page: 1,
        limit: 10,
        start_time: null,
        end_time: null
      },
      tableData: [],
      totalPage: 0,
      isBack: false
    }
  },
  // watch: {
  //   '$route.query': {
  //     handler(newval) {
  //       console.log(newval)
  //       if (newval && newval.isBack) {
  //         this.isBack = newval.isBack
  //       } else {
  //         this.isBack = 0
  //       }
  //     },
  //     deep: true
  //   }
  // },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      seviceApi.getIntegralPTRegiftList(this.pamars).then(res => {
        if (res && res.data.code == 200) {
          this.tableData = res.data.page.list
          this.totalPage = res.data.page.totalCount
        }
      })
    },
    timerChange(e) {
      console.log(e)
      if (e) {
        this.pamars.start_time = e[0]
        this.pamars.end_time = e[1]
      } else {
        this.pamars.start_time = null
        this.pamars.end_time = null
      }
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pamars.limit = val
      this.getList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pamars.page = val
      this.getList()
    },
    // 查询
    getDataList() {
      this.pamars.page = 1
      this.getList()
    },
    resetPamars() {
      this.timer = null
      this.pamars.start_time = null
      this.pamars.end_time = null
      this.$refs.formRef.resetFields()
      this.getDataList()
    },
    goBack() {
      this.$router.back()
    }
  }
}
</script>

<style lang="scss" scoped></style>
